/*************************************************************************************************
 * Class to represent a square. The class inherits perfect polygon. 
 * A square is characterized by 4 sides and their length. Its area is (side-length)^2. 
 *************************************************************************************************/

package geometricElement;

public class Square extends PerfectPolygon {

	// members
	private static final int sides  = 4; // a square has 4 sides
	
	// methods
	/*************************************************************************************************
	 * Function name: public Square(int xCord, int yCord, double length)
	 * Input: Position and side's length
	 * Output: None
	 * Function operation: Constructor- creates a new square with given values, using PerfectPolygon's
	 * 					   constructor
	 *************************************************************************************************/
	public Square(int xCord, int yCord, double length) {
		// set members with given value
		super(xCord, yCord, length, sides);
		// set area according to square's method
		setArea(calculateArea());
	}
	
	/*************************************************************************************************
	 * Function name: public double calculateArea()
	 * Input: None
	 * Output: Circle's area
	 * Function operation: Calculates square's area and returns it
	 *************************************************************************************************/
	public double calculateArea() {
		// square's area is (side-length)^2
		return getLength()*getLength();
	}

	/*************************************************************************************************
	 * Function name: public Square clone()
	 * Input: None
	 * Output: Reference to square's copy
	 * Function operation: Allocates a new square with activating square's attributes and returns a 
	 * 					   reference to the copy 
	 *************************************************************************************************/
	public Square clone() {
		// return reference to object's copy
		return new Square(getXcord(), getYcord(), getLength());
	}

	public String toString() {
		return "Type: Square, " + super.toString();
	}
}
